<template>
  <el-drawer
    v-model="showDrawer"
    :close-on-click-modal="false"
    :title="title"
    :size="size"
    :destory-on-close="destoryOnClose"
  >
    <div class="formDrawer">
      <div class="body">
        <solt></solt>
      </div>
      <div class="actions">
        <el-button type="primary" @click="submit" loading="loading"> {{ confirmText }} </el-button>
        <el-button @click="close"> 取消 </el-button>
      </div>
    </div>
  </el-drawer>
</template>

<script setup>
import { ref } from "vue";

const showDrawer = ref(false);

// 打开
const open = () => (showDrawer.value = true);
// 关闭
const close = () => (showDrawer.value = false);

const showLoading = () => showLoading.value = true
const hideLoading = () => showLoading.value = false


const emit = defineEmits(["submit"])
const submit = () => emit("submit")

// 暴露方法
defineExpose({
  open,
  close,
  showLoading,
  hideLoading
});

const props = defineProps({
  title: String,
  size: {
    type: String,
    default: "45%",
  },
  destoryOnClose: {
    type: Boolean,
    default: false,
  },
  confirmText: {
    type: String,
    default: "提交",
  },
});


const loading = ref(false)
</script>

<style>
.formDrawer {
  width: 100%;
  height: 100%;
  position: relative;
  @apply flex flex-col;
}
.formDrawer .body {
  flex: 1;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 50px;
  overflow-y: auto;
}

.formDrawer .actions {
  height: 50px;
  @apply mt-auto flex items-center;
}
</style>
